<?php
/**************************************************************************
 *
 *   Copyright 2010 American Public Media Group
 *
 *   This file is part of AIR2.
 *
 *   AIR2 is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   AIR2 is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with AIR2.  If not, see <http://www.gnu.org/licenses/>.
 *
 *************************************************************************/

/*
|--------------------------------------------------------------------------
| AIR2 Inquiry search page
|--------------------------------------------------------------------------
*/
$search_url = $c->uri_for('search.json', array('gzip' => $use_gzip, 'i'=>'inquiries'));
$inquiry_url = $c->uri_for('inquiry');
?>
<script type="text/javascript">
    Ext.onReady(function() {

        AIR2.Search.URL     = '<?php echo $c->uri_for("search") ?>';
        AIR2.Search.QUERY   = '<?php echo htmlspecialchars($q, ENT_QUOTES) ?>';
        AIR2.Search.PARAMS  = <?php echo Encoding::json_encode_utf8($params) ?>;
        AIR2.Search.IDX     = 'inquiries';

        var resultTpl = new Ext.XTemplate(
           '<tpl for=".">',
            '<div class="air2-search-result">',
             '<div class="link">',
              '<h3><a class="title" href="<?php echo $inquiry_url ?>/{uri}">{title}</a></h3>',
             '</div>',
             '<div>',
              'Tags: <b>',
              '<tpl for="tag"',
               '<span class="tag">',
                '<a href="<?php echo $c->uri_for("search") ?>/inquiries/?q=',
                '{[encodeURIComponent("tag=("+AIR2.Search.cleanQueryForTag(values)+")")]}">{.}',
                '</a>',
               '</span>',
               '{[xindex != xcount ? ", " : "" ]}',
              '</tpl>',
              '</b><br/>',
              'Projects: <b>',
              '<tpl for="prj_display_name">',
               '<span class="project">',
               '{[AIR2.Format.projectName( { prj_display_name:values, prj_uuid:parent.prj_uuid[xindex-1] }, true)]}',
               '</span>',
               '{[xindex != xcount ? ", " : "" ]}',
              '</tpl>',
              '</b><br/>',
              'Author: <b>{author}</b><br/>',
              'Internal title: <b>{inq_title}</b><br/>',
              'Last updated: <b>{inq_upd_dtim}</b><br/>',
              'Number of responses: <b><a href="<?php echo $c->uri_for("search") ?>/responses/?q=',
              '{["inq_uuid%3d"+values.inq_uuid]}">{response_sets_count}</a></b><br />',
             '</div>',
             '<div class="summary">{summary}</div>',
            '</div>',
           '</tpl>'
        );

        var facetDefs = {

            org_uuid : {
                label : 'Organization',
                itemLabels : <?php echo Encoding::json_encode_utf8($org_names) ?>
            },

            tag : {
                label : 'Tag'
            },

            prj_uuid_title : {
                label : 'Project',
                itemLabels : <?php echo Encoding::json_encode_utf8($prj_names) ?>
            },

            inq_type : {
                label : 'Type'
            },

            srs_ts   : {
                label : 'Responses by Date'
            },

            author   : {
                label : 'Author'
            }

        };

        var app = new AIR2.UI.App({
            items: AIR2.SearchPanel({
                title       : 'Queries',
                searchUrl   : '<?php echo $search_url ?>',
                resultTpl   : resultTpl,
                facetDefs   : facetDefs
            })
        });

    });
</script>
